FROM ubuntu:20.04

ENV cmdVersion=6.5.3.6
ENV PATH=/opt/sencha/cmd/${cmdVersion}/:$PATH
ENV PJS_HOME=/usr/lib/phantomjs
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai

# ENV http_proxy=socks5://192.168.3.98:7897
# ENV https_proxy=socks5://192.168.3.98:7897
# ENV all_proxy=socks5://192.168.3.98:7897

EXPOSE 1841

# 安装依赖
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y \
      locales-all \
      git \
      openjdk-8-jre-headless \ 
      ruby \
      build-essential \
      libstdc++6 \
      tzdata \
      bash \
      fonts-dejavu \
      libfreetype6 \
      fontconfig \
      curl \
      unzip \
      xz-utils \
      ca-certificates && \
    rm -rf /var/lib/apt/lists/*

ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8

# 创建目录
RUN mkdir -p /sdk /opt/sencha/cmd/${cmdVersion}

# 拷贝 Ext JS SDK 到容器中并解压
COPY ext-6.2.0-gpl.zip /sdk/
WORKDIR /sdk
RUN unzip ext-6.2.0-gpl.zip -d /sdk/ && \
    rm /sdk/ext-6.2.0-gpl.zip

# 安装 Sencha CMD（使用本地文件）
COPY SenchaCmd-6.5.3.6-linux-amd64.sh.zip /tmp/
WORKDIR /tmp
RUN unzip SenchaCmd-6.5.3.6-linux-amd64.sh.zip -d /tmp && \
    rm /tmp/SenchaCmd-6.5.3.6-linux-amd64.sh.zip && \
    chmod +x SenchaCmd-6.5.3.6-linux-amd64.sh && \
    export JAVA_TOOL_OPTIONS="-Djava.awt.headless=true" && \
    ./SenchaCmd-6.5.3.6-linux-amd64.sh -q -dir /opt/sencha/cmd/${cmdVersion} -Dall=true && \
    rm SenchaCmd-6.5.3.6-linux-amd64.sh && \
    chmod +x /opt/sencha/cmd/${cmdVersion}/sencha

# 安装 PhantomJS（使用本地文件）
COPY phantomjs-2.1.1-linux-x86_64.tar.bz2 /tmp/
RUN tar -xjf /tmp/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/ && \
    ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/ && \
    rm /tmp/phantomjs-2.1.1-linux-x86_64.tar.bz2

# 创建工作目录
WORKDIR /code
COPY . .

CMD ["bash"]